import repository from '../repository'
import locationService from './LocationService'
class ShopService {
  async getShopListByCategory (params) {
    const data = await repository.getShopByCategory({
      location: locationService.getLocation().location,
      ...params
    })
    if (!data.success) {
      throw new Error(`获取分类${params.categoryId}下的店铺失败:${data.msg}`)
    }
    return data.data
  }

  async getNearyByShop () {
    const data = await repository.getNearByShop()
    console.log(data.data)
    // if (data.code == 500) {
    //   throw new Error('获取餐品列表失败:' + data.msg)
    // }
   // console.log(data.data)
    return data.data
  }

  async searchShop (params) {
    const data = await repository.searchShop(params)
    if (!data.success) {
      throw new Error('搜索店铺失败:' + data.msg)
    }
    return data.data
  }

  async getShopInfo (shopId) {
    const data = await repository.getShopInfo(shopId)
    return data.data
  }

  async getShopProductCategory () {
    const data = await repository.getShopProductCategory()
   
    return data.data
  }

  async getProductList (categoryId) {
    const data = await repository.getProductList(categoryId)
    
    const productList = data.data
    // 设置默认选中规格
  
    return productList
  }

  //显示商家评论信息
  async getShopEval () {
    const data = await repository.getShopEval()
    return data.data
  }

  //评论列表
  async getShopEvalList (params) {
    const data = await repository.getShopEvalList(params)
    console.log("---------------------分割线---------------------------")
    
    return data.data
  }
  //添加评论
  async addEval(params){
    params = JSON.parse(JSON.stringify(params))
    
    console.log(params)
    const data = await repository.addEval(params)
    return data.data
  }
}
export default new ShopService()
